package com.sangmo.fts.process.storage.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "csf_stock")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class CsfStock extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, index = true, unique = true)
    private String code;

    @One(value = "waybill", target = CsfWaybill.class, groups = {"CsfStock.search","CsfStock.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long waybillId;

    @One(value = "agreement", target = CsfAgreement.class, groups = {"CsfStock.search","CsfStock.detail"}, fieldset = {"id", "code"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long agreementId;

    @One(value = "bailorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long bailor;

    @DataField(required = true)
    private Date storageTime;

    @DataField(value = IConstants.DATA_TYPE.DATE_BEGIN)
    private Date startTime;

    @DataField(value = IConstants.DATA_TYPE.DATE_END)
    private Date endTime;

    private Long confirmDoc;

    @DataField(value = IConstants.CSF_STOCK_DATA_TYPE.STOCK_STATE, required = true, index = true)
    private String state = States.SUBMITTING;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getWaybillId() {
        return waybillId;
    }

    public void setWaybillId(Long waybillId) {
        this.waybillId = waybillId;
    }

    public Long getAgreementId() {
        return agreementId;
    }

    public void setAgreementId(Long agreementId) {
        this.agreementId = agreementId;
    }

    public Long getBailor() {
        return bailor;
    }

    public void setBailor(Long bailor) {
        this.bailor = bailor;
    }

    public Date getStorageTime() {
        return storageTime;
    }

    public void setStorageTime(Date storageTime) {
        this.storageTime = storageTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Long getConfirmDoc() {
        return confirmDoc;
    }

    public void setConfirmDoc(Long confirmDoc) {
        this.confirmDoc = confirmDoc;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public interface States {
        String SUBMITTING = "SUBMITTING"; //待提交
        String PENDING = "PENDING"; //待确认
        String CONFIRMED = "CONFIRMED"; //已确认
    }
}
